#pragma once
#include <functional>
#include <memory>
#include <vector>

namespace UTILS {
template <typename T> class SimpleObjectPool {
public:
  using DeleterType = std::function<void(T *)>;

  void add(std::shared_ptr<T> t) { pool_.push_back(std::move(t)); }

  std::shared_ptr<T> get() {
    if (pool_.empty()) {
      throw std::logic_error("no more object");
    }

    // every time add custom deleter for default shared_ptr
    std::shared_ptr<T> ptr(pool_.back());

    pool_.pop_back();
    return std::move(ptr);
  }

  bool empty() const { return pool_.empty(); }

  size_t size() const { return pool_.size(); }

private:
  std::vector<std::shared_ptr<T>> pool_;
};
} // namespace UTILS